{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "import tensorflow as tf\n",
    "import tf_encrypted as tfe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Turn on TFE debugging flags first thing, optionally specifying where logging files should be written."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tf_encrypted:Tensorflow encrypted is dumping computation traces\n",
      "INFO:tf_encrypted:Writing event and trace files to '/tmp/tensorboard'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Tensorflow encrypted is monitoring statistics for each', 'session.run() call using a tag')\n"
     ]
    }
   ],
   "source": [
    "%load_ext tensorboard.notebook\n",
    "\n",
    "TENSORBOARD_DIR = \"/tmp/tensorboard\"\n",
    "\n",
    "tfe.set_tfe_trace_flag(True)\n",
    "tfe.set_tfe_events_flag(True)\n",
    "tfe.set_log_directory(TENSORBOARD_DIR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computation\n",
    "\n",
    "Define whatever computation we wish to inspect. Here we just do a few simple operations that TensorFlow can optimize: the `add` calls can be replaced with `add_n`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = tfe.define_private_input(\"input-provider\", lambda: tf.fill([2,2], 2))\n",
    "\n",
    "y = x + x + x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Execution\n",
    "\n",
    "We first remove previous event and tracing files to make it easier to find the new runs in TensorBoard."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tf_encrypted:Players: ['server0', 'server1', 'server2', 'input-provider']\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[6. 6.]\n",
      " [6. 6.]]\n"
     ]
    }
   ],
   "source": [
    "!rm -rf {TENSORBOARD_DIR}\n",
    "\n",
    "with tfe.Session(disable_optimizations=True) as sess:\n",
    "    res = sess.run(y.reveal(), tag='res', output_partition_graphs=True)\n",
    "    print(res)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Inspection\n",
    "\n",
    "Let's first see what's in the logging directory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 40\r\n",
      "drwxr-xr-x  6 dahl  wheel    192 May 21 14:21 \u001b[1m\u001b[36mres0\u001b[m\u001b[m\r\n",
      "-rw-r--r--  1 dahl  wheel  20299 May 21 14:21 res0.ctr\r\n"
     ]
    }
   ],
   "source": [
    "!ls -l {TENSORBOARD_DIR}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we have a trace file, `res0.ctr`, for each tagged run that can e.g. be viewed in Google Chrome using [`chrome://tracing/`](chrome://tracing/). We also have a directory with event and partition files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 104\r\n",
      "-rw-r--r--  1 dahl  wheel  28178 May 21 14:21 events.out.tfevents.1558441303.WorkBook.local\r\n",
      "-rw-r--r--  1 dahl  wheel  11510 May 21 14:21 partition0.pbtxt\r\n",
      "-rw-r--r--  1 dahl  wheel   5007 May 21 14:21 partition1.pbtxt\r\n",
      "-rw-r--r--  1 dahl  wheel   2108 May 21 14:21 partition2.pbtxt\r\n"
     ]
    }
   ],
   "source": [
    "!ls -l {TENSORBOARD_DIR}/res0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All of these can be viewed using TensorBoard as shown below, but occasionally it's also useful to look directly at the partition protobuf files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "node {\r\n",
      "  name: \"ConstantFolding/decode/truediv_recip\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_DOUBLE\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_DOUBLE\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        tensor_content: \"\\225yT\\2539\\372#?\"\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"ConstantFolding/decode/truediv_recip\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/sub/y\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: 14348907\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/sub/y\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/expand-seed/max\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: 9223372036854775807\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/expand-seed/max\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/expand-seed/min\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: -9223372036854775808\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/expand-seed/min\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT32\r\n",
      "        tensor_shape {\r\n",
      "          dim {\r\n",
      "            size: 2\r\n",
      "          }\r\n",
      "        }\r\n",
      "        tensor_content: \"\\002\\000\\000\\000\\002\\000\\000\\000\"\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed_1/max\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: 9223372036854775807\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed_1/max\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed_1/min\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: -9223372036854775808\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed_1/min\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed_1/SecureSeededRandomUniform/shape\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT32\r\n",
      "        tensor_shape {\r\n",
      "          dim {\r\n",
      "            size: 2\r\n",
      "          }\r\n",
      "        }\r\n",
      "        tensor_content: \"\\002\\000\\000\\000\\002\\000\\000\\000\"\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed_1/SecureSeededRandomUniform/shape\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed/max\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r",
      "\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: 9223372036854775807\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed/max\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed/min\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "        }\r\n",
      "        int64_val: -9223372036854775808\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed/min\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT32\r\n",
      "        tensor_shape {\r\n",
      "          dim {\r\n",
      "            size: 2\r\n",
      "          }\r\n",
      "        }\r\n",
      "        tensor_content: \"\\002\\000\\000\\000\\002\\000\\000\\000\"\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/Const\"\r\n",
      "  op: \"Const\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"value\"\r\n",
      "    value {\r\n",
      "      tensor {\r\n",
      "        dtype: DT_INT64\r\n",
      "        tensor_shape {\r\n",
      "          dim {\r\n",
      "            size: 1\r\n",
      "          }\r\n",
      "        }\r\n",
      "        int64_val: 14348907\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/Const\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"private-input/share/SecureSeed/_1\"\r\n",
      "  op: \"_Recv\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"client_terminated\"\r\n",
      "    value {\r\n",
      "      b: false\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"recv_device\"\r\n",
      "    value {\r\n",
      "      s: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"send_device\"\r\n",
      "    value {\r\n",
      "      s: \"/job:localhost/replica:0/task:0/device:CPU:3\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"send_device_incarnation\"\r\n",
      "    value {\r\n",
      "      i: 1\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"tensor_name\"\r\n",
      "    value {\r\n",
      "      s: \"edge_3_private-input/share/SecureSeed\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"tensor_type\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"private-input/share/SecureSeed\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  op: \"SecureSeededRandomUniform\"\r\n",
      "  input: \"add_1/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  input: \"private-input/share/SecureSeed/_1\"\r\n",
      "  input: \"add_1/expand-seed/min\"\r\n",
      "  input: \"add_1/expand-seed/max\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"Tseed\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed_1/SecureSeededRandomUniform\"\r\n",
      "  op: \"SecureSeededRandomUniform\"\r\n",
      "  input: \"add/expand-seed_1/SecureSeededRandomUniform/shape\"\r\n",
      "  input: \"private-input/share/SecureSeed/_1\"\r\n",
      "  input: \"add/expand-seed_1/min\"\r\n",
      "  input: \"add/expand-seed_1/max\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"Tseed\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed_1/SecureSeededRandomUniform\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  op: \"SecureSeededRandomUniform\"\r\n",
      "  input: \"add/expand-seed/SecureSeededRandomUniform/shape\"\r\n",
      "  input: \"private-input/share/SecureSeed/_1\"\r\n",
      "  input: \"add/expand-seed/min\"\r\n",
      "  input: \"add/expand-seed/max\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"Tseed\"\r\n",
      "    value {\r\n",
      "      type: DT_INT32\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"dtype\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add/add\"\r\n",
      "  op: \"Add\"\r\n",
      "  input: \"add/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  input: \"add/expand-seed_1/SecureSeededRandomUniform\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add/add\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/add\"\r\n",
      "  op: \"Add\"\r\n",
      "  input: \"add/add\"\r\n",
      "  input: \"add_1/expand-seed/SecureSeededRandomUniform\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/add\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"add_1/add_1/_5\"\r\n",
      "  op: \"_Recv\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"client_terminated\"\r\n",
      "    value {\r\n",
      "      b: false\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"recv_device\"\r\n",
      "    value {\r\n",
      "      s: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"send_device\"\r\n",
      "    value {\r\n",
      "      s: \"/job:localhost/replica:0/task:0/device:CPU:1\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"send_device_incarnation\"\r\n",
      "    value {\r\n",
      "      i: 1\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"tensor_name\"\r\n",
      "    value {\r\n",
      "      s: \"edge_29_add_1/add_1\"\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"tensor_type\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"add_1/add_1\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"reveal/add\"\r\n",
      "  op: \"Add\"\r\n",
      "  input: \"decode/Const\"\r\n",
      "  input: \"add_1/add_1/_5\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"reveal/add\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/add\"\r\n",
      "  op: \"Add\"\r\n",
      "  input: \"reveal/add\"\r\n",
      "  input: \"add_1/add\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/add\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/sub\"\r\n",
      "  op: \"Sub\"\r\n",
      "  input: \"decode/add\"\r\n",
      "  input: \"decode/sub/y\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/sub\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/truediv/Cast\"\r\n",
      "  op: \"Cast\"\r\n",
      "  input: \"decode/sub\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"DstT\"\r\n",
      "    value {\r\n",
      "      type: DT_DOUBLE\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"SrcT\"\r\n",
      "    value {\r\n",
      "      type: DT_INT64\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"Truncate\"\r\n",
      "    value {\r\n",
      "      b: false\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/truediv/Cast\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"decode/truediv\"\r\n",
      "  op: \"Mul\"\r\n",
      "  input: \"decode/truediv/Cast\"\r\n",
      "  input: \"ConstantFolding/decode/truediv_recip\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_DOUBLE\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"decode/truediv\"\r\n",
      "  }\r\n",
      "}\r\n",
      "node {\r\n",
      "  name: \"_retval_decode/truediv_0_0\"\r\n",
      "  op: \"_Retval\"\r\n",
      "  input: \"decode/truediv\"\r\n",
      "  device: \"/job:localhost/replica:0/task:0/device:CPU:0\"\r\n",
      "  attr {\r\n",
      "    key: \"T\"\r\n",
      "    value {\r\n",
      "      type: DT_DOUBLE\r\n",
      "    }\r\n",
      "  }\r\n",
      "  attr {\r\n",
      "    key: \"index\"\r\n",
      "    value {\r\n",
      "      i: 0\r\n",
      "    }\r\n",
      "  }\r\n",
      "  experimental_debug_info {\r\n",
      "    original_node_names: \"_retval_decode/truediv_0_0\"\r\n",
      "  }\r\n",
      "}\r\n",
      "library {\r\n",
      "}\r\n",
      "versions {\r\n",
      "  producer: 27\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!cat {os.path.join(TENSORBOARD_DIR, \"res0/partition0.pbtxt\")}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can load these files in TensorBoard via `Choose File`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Reusing TensorBoard on port 6010 (pid 64858), started -1 day, 23:06:21 ago. (Use '!kill 64858' to kill it.)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"100%\"\n",
       "            height=\"600\"\n",
       "            src=\"http://localhost:6010\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x10df27320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%tensorboard --logdir {TENSORBOARD_DIR}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
